<%@page import="java.text.SimpleDateFormat"%>
<%@page pageEncoding="UTF-8" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.Date" %>
<%@page import="com.webdemo3.dao.UsersDao" %>
<%@page import="com.webdemo3.bean.UsersBean" %>
<%@include file="_sessionCheck.jsp"%>
<%
	final int PAGE_SIZE = 2;
	int pageNo = 1;
	boolean headState = false;
	boolean trailState = false;
	String startPage = request.getParameter("pageno");
	if(startPage != null && !startPage.trim().equals("")) {
		try {
			pageNo = Integer.parseInt(startPage);
		} catch(NumberFormatException e) {
			pageNo = 1;
		}
	}
	int totalRecords = UsersDao.getTotalRecords();
	int totalPage = (totalRecords % PAGE_SIZE == 0) ? (totalRecords / PAGE_SIZE) : (totalRecords / PAGE_SIZE + 1); 
	if(pageNo <= 1 ) {
		pageNo = 1;
		headState = true;
	}
	if(pageNo >= totalPage) {
		pageNo = totalPage;
		trailState = true;
	}
	int startPos = (pageNo - 1) * PAGE_SIZE;
	
%>

<%
	List<UsersBean> usersList = UsersDao.search(startPos, PAGE_SIZE);
	String username = session.getAttribute("username").toString();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息</title>
<style>
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.table1 {
	border-left:1px #06F solid;
	border-top:1px #06F solid;
}
.td1 {
	border-right:1px #06F solid;
	border-bottom:1px #06F solid;
}
</style>
<script type="text/javascript">
	function getCurrentTime() {
		var d = new Date();
		document.getElementById("span1").innerHTML = d.toLocaleString(); 
	}
	setInterval("getCurrentTime()", 1000);
</script>
</head>

<body>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td class="td" style="font-size:50px; padding:15px 5px">公司logo</td>
    <td width="300">&nbsp;</td>
  </tr>
  <tr>
    <td>欢迎：<%=username %> <a href="exit.jsp">安全退出</a></td>
    <td>当前时间&nbsp;<span id="span1"></span></td>
  </tr>
  <tr>
  	<th colspan="2" style="font-size:20px;padding:15px 5px;background-color:#939">用户信息</th>
  </tr>
</table>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0" class="table1">
  <tr>
    <td width="100" align="center" class="td1">用户名</td>
    <td align="center" class="td1">性别</td>
    <td align="center" class="td1">电话</td>
    <td width="200" align="center" class="td1">地址</td>
    <td align="center" class="td1">生日</td>
    <td align="center" class="td1">注册时间</td>
    <td align="center" class="td1">操作</td>
  </tr>
  
  <%
  	for(int i = 0; i < usersList.size(); i++) {
  		UsersBean ub = usersList.get(i);
  %>
  
  <tr>
    <td width="130" align="center" class="td1"><%=ub.getUsername() %></td>
    <td width="60" align="center" class="td1"><%=ub.getGender() %></td>
    <td width="110" align="center" class="td1"><%=ub.getPhone() %></td>
    <td align="center" class="td1"><%=ub.getAddr() %></td>
    <td width="100" align="center" class="td1"><%=ub.getBirth() %></td>
    <td width="170" align="center" class="td1"><%=ub.getRegDate() %></td>
    <td width="80" align="center" class="td1"><a href="update.jsp?username=<%=ub.getUsername()%>">修改</a> <a href="deleteProcess.jsp?username=<%=ub.getUsername() %>" onclick="return  confirm('确认删除')">删除</a></td>
  </tr>
  <%
  	}
  %>
</table>
<table align="center">
	<tr>
		<%
			if(headState) {
		%>
		<td>首页</td>
		<td>上一页</td>
		<%
			} else { 
		%>
		<td><a href="list.jsp?pageno=1">首页</a></td>
		<td><a href="list.jsp?pageno=<%=pageNo - 1%>">上一页</a></td>
		<%
			}
		%>
		<%
			for(int i = 1; i <= totalPage; i++) {
		%>
		<td><a href="list.jsp?pageno=<%=i %>"><%=i %></a></td>
		<%
			}
		%>
		
		<%
			if(trailState) {
		%>
		<td>下一页</td>
		<td>末页</td>
		<%
			} else { 
		%>
		<td><a href="list.jsp?pageno=<%=pageNo + 1%>">下一页</a></td>
		<td><a href="list.jsp?pageno=<%=totalPage %>">末页</a></td>
		<%
			}
		%>
	</tr>
</table>
</body>
</html>
